//
//  YNMessageContactManager.m
//  Messenger
//
//  Created by iOS on 15/4/21.
//  Copyright (c) 2015年 YN-APP-iOS. All rights reserved.
//

#import "YNMessageContactManager.h"
#import "YNMessage.h"
#import "YNRecentChatObejct.h"
#import "YNContactManager.h"
#import "XMPPDBManager.h"
#import "YNTwoPeopleChat.h"
#import "YNManyPeopleChat.h"
#import "YNUser.h"
#import "YNBroadcastChat.h"
#import "YNBroadcastNotificationChat.h"
#import "FMDatabase.h"
#import "FMDatabaseQueue.h"
#import "FMDatabaseAdditions.h"
#import "YNIMFrameworkMacro.h"

@implementation YNMessageContactManager
static FMDatabaseQueue *_queue;

static FMDatabase *_db;

#pragma mark - 更新会话消息

+ (BOOL)updateChatWithMessage:(YNMessage *)message changRecentChat:(BOOL)isChange
{
    //更新最近会话
    __block BOOL result;
    if (isChange)
    {
        YNRecentChatObejct *recentChat = [self creatRecentChatWithMessage:message];
        result = [YNContactManager saveRecentChatWithMessage:recentChat isFromRoamingSource:NO];
    }
    
    _queue = [[XMPPDBManager sharedInstance] achieveQueue];
    [_queue inTransaction:^(FMDatabase *db, BOOL *rollback){
        //更新数据库里面的消息
        switch (message.chatType) {
                 case YNBubbleMessageChatTypeWeChat:
                 case YNBubbleMessageChatTypeWeChatVoice:
                
                [YNTwoPeopleChat updateTwoPeopleChatTableWithMessageID:message.packetId
                                                              sendTime:message.sendTime
                                                             isSuccess:message.sendState
                                                            inDatabase:db];
                break;
                case YNBubbleMessageChatTypeGroupChat:
                case YNBubbleMessageChatTypeGroupChatVoice:
                
                [YNManyPeopleChat updateManyPeopleChatTableWithMessageID:message.packetId
                                                                sendTime:message.sendTime
                                                               groupType:kContact_UserGroupType
                                                               isSuccess:message.sendState
                                                              inDatabase:db];
                break;
                case YNBubbleMessageChatTypeDiscussion:
                case YNBubbleMessageChatTypeDiscussionVoice:
                
                [YNManyPeopleChat updateManyPeopleChatTableWithMessageID:message.packetId
                                                                sendTime:message.sendTime
                                                               groupType:kContact_DiscussionGropType
                                                               isSuccess:message.sendState
                                                              inDatabase:db];
                break;
            case YNBubbleMessageChatTypeProjectTeamChat:
            case YNBubbleMessageChatTypeProjectTeamVoice:
                
                [YNManyPeopleChat updateManyPeopleChatTableWithMessageID:message.packetId
                                                                sendTime:message.sendTime
                                                               groupType:kContact_ProjectTeamGropType
                                                               isSuccess:message.sendState
                                                              inDatabase:db];
                break;
            case YNBubbleMessageChatTypeBroadcast:
                
                debugLog(@"目前还没有处理广播消息");
                break;
            case YNBubbleMessageChatTypeNotification:
                
                debugLog(@"目前还没有处理通知消息");
                break;
            default:
                debugLog(@"未知类型:%s - %s + %d", __FILE__, __FUNCTION__, __LINE__);
                break;
        }
        
        if (!isChange)
        {
            result = [YNRecentChatObejct updateRecentChatTableWithUseNo:message.toUserId
                                                                 sendTime:message.sendTime
                                                                isSuccess:message.sendState
                                                               inDatabase:db];
        }
        result = *rollback;
    }];
    return result;
}

//返回一个最近会话duixiang
+ (YNRecentChatObejct *)creatRecentChatWithMessage:(YNMessage *)message
{
    YNRecentChatObejct *recentChat = [[YNRecentChatObejct alloc] init];
    //保存最近会话到数据库
    recentChat.userNo = message.friendId;
    recentChat.content = message.text;
    recentChat.chatType = message.chatType;
    recentChat.sendNo = message.fromUserId;
    recentChat.dataTime = message.sendTime;
    recentChat.topTime = nil;
    recentChat.headUrl = nil;
    recentChat.headLocalPath = nil;
    recentChat.isTop = kFlag_UnKnowTop;
    recentChat.unReadCount = 0;
    recentChat.sendState = YNMessageSendStateSending;
    recentChat.messageBody = message.message;
    recentChat.messageType = message.messageMediaType;
    recentChat.masterRecentType=message.bubbleMessageType;
    recentChat.packId = message.packetId;
    
    if (message.chatType == YNBubbleMessageChatTypeWeChat || message.chatType == YNBubbleMessageChatTypeWeChatVoice || message.chatType == YNBubbleMessageChatTypeFileWeChat)
    {
        YNUser *user;
        if(message.chatType == YNBubbleMessageChatTypeWeChat || message.chatType == YNBubbleMessageChatTypeFileWeChat)
        {
            user= [YNContactManager queryUserNameByUserID:message.friendId chatType:YNBubbleMessageChatTypeWeChat];
        }
        else
        {
            user = [YNContactManager queryUserNameByUserID:message.friendId chatType:YNBubbleMessageChatTypeWeChatVoice];
        }
        recentChat.title = user.userName;
        recentChat.text = message.text;
    }
    else if (message.chatType == YNBubbleMessageChatTypeGroupChat || message.chatType == YNBubbleMessageChatTypeDiscussion || message.chatType == YNBubbleMessageChatTypeProjectTeamChat || message.chatType == YNBubbleMessageChatTypeGroupChatVoice ||  message.chatType == YNBubbleMessageChatTypeDiscussionVoice ||  message.chatType == YNBubbleMessageChatTypeProjectTeamVoice)
    {
        recentChat.senderName = [YNIMmanager sharedInstance].userName;
        recentChat.title = message.groupName;
        recentChat.text = message.text;
    }
    
    return recentChat;
}


+ (BOOL)updateUnReadMessageNumberWithIdentify:(NSString *)identify
{
     FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback){
        
        result = [YNRecentChatObejct unReadNumberMakeZeroWithUserNo:identify Database:db];
        
        //result = !*rollback;
        
    }];
    return result;
}
/**JC** 将isNewListPullData更新为YES，表示已经拉取过消息漫游 **/
+ (BOOL)updateRecentNewListPullDataUnreadCountByOneWithUserNo:(NSString *)userNo
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback){
        
        result = [YNRecentChatObejct updateRecentNewListPullDataUnreadCountByOneWithUserNo:userNo Database:db];
        
    }];
    return result;
}

/**
 修改撤回状态  2018.11.27jc添加
 
 @param chatId 对方id
 @param packId 消息id
 @return
 */
+(BOOL)updateRecentChatWithdrawWithChatId:(NSString *)chatId packId:(NSString *)packId
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback){
        
        result = [YNRecentChatObejct updateRecentChatWithdrawWithChatId:chatId packId:packId inDatabase:db];
        
    }];
    return result;
}


+ (BOOL)updateMessageHeightWithMessage:(YNMessage*)message
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback){
        
        switch (message.chatType) {
                case YNBubbleMessageChatTypeWeChat:
                case YNBubbleMessageChatTypeWeChatVoice:
                case YNBubbleMessageChatTypeFileWeChat:
               result = [YNTwoPeopleChat updateTwoPeopleChatTableWithMessageID:message.packetId
                                                         messageHeight:message.messageHeight
                                                            inDatabase:db];
                break;
                case YNBubbleMessageChatTypeGroupChat:
                case YNBubbleMessageChatTypeGroupChatVoice:
                result = [YNManyPeopleChat updateManyPeopleChatTableWithMessageID:message.packetId
                                                           messageHeight:message.messageHeight
                                                               groupType:kContact_UserGroupType
                                                              inDatabase:db];
                break;
                case YNBubbleMessageChatTypeDiscussion:
                case YNBubbleMessageChatTypeDiscussionVoice:
                result = [YNManyPeopleChat updateManyPeopleChatTableWithMessageID:message.packetId
                                                           messageHeight:message.messageHeight
                                                               groupType:kContact_DiscussionGropType
                                                              inDatabase:db];
                break;
            case YNBubbleMessageChatTypeProjectTeamChat:
            case YNBubbleMessageChatTypeProjectTeamVoice:
                result = [YNManyPeopleChat updateManyPeopleChatTableWithMessageID:message.packetId
                                                                    messageHeight:message.messageHeight
                                                                        groupType:kContact_ProjectTeamGropType
                                                                       inDatabase:db];
                break;
            default:
                break;
        }
       // result = *rollback;
    }];
    
    return result;
}

#pragma mark - Broadcast Mothed

+ (BOOL)saveBroadcastWithMessage:(YNBroadcastChat *)broadcast
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        
        result = [broadcast insertBroadcastMessageInDatabase:db];
        
    }];
    return result;
}

+ (BOOL)updateIsReadToReadInDatabaseWithPacketid:(NSString *)packetid
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        
        result = [YNBroadcastChat updateIsReadToReadInDatabase:db packetId:packetid];
        
    }];
    return result;
}

+ (BOOL)deleteBroadcastMessageWithPacketId:(NSString *)packetId
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback){
        
        if (packetId)
        {
            result = [YNBroadcastChat deleteBroadcastWithPacketId:packetId inDatabase:db];
        }
        else
        {
            result = [YNBroadcastChat deleteALLBroadcastInDatabase:db];
        }

    }];
    return result;
}

+ (NSArray *)queryBroadcastWithStartIndex:(NSInteger)start
                                 endIndex:(NSInteger)end
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];

    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    __block NSArray *broadcastArray;
    
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback){
       
        broadcastArray = [YNBroadcastChat queryBroadcastWithStartIndex:start
                                                              endIndex:end
                                                            inDatabase:db];
        
        
        dispatch_semaphore_signal(semaphore);
    }];
    
    dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
    
    return broadcastArray;
}

#pragma mark - Broadcast Notification Mothed

//保存广播通知数据(一条)
+ (BOOL)saveBroadcastNotificationWithMessage:(YNBroadcastNotificationChat *)notification
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        
        result = [notification insertBroadcastNotificationInDatabase:db];
        //result = *rollback;
    }];
    return result;
}

//删除广播通知数据
+ (BOOL)deleteBroadcastNotificationWithObject:(id)object
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
       
        if ([object isKindOfClass:[NSString class]])
        {
            result = [YNBroadcastNotificationChat deleteBroadcastNotificationWithPacketId:object inDatabase:db];
        }
        else if ([object isKindOfClass:[NSArray class]])
        {
            result = [YNBroadcastNotificationChat deleteBroadcastWithNotificationTypeArray:object inDatabase:db];
        }
       // result = *rollback;
    }];
    return result;
}

//
+ (BOOL)updateUnReadBroadNotificationWithType:(YNBroadcastNotificationType)broadcastNotificationType pocketId:(NSString *)pocketId
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        
        if (pocketId)//不为空则更新单条通知
        {
             result = [YNBroadcastNotificationChat updateOneBroadcastNotificationWithPacketId:pocketId inDatabase:db];
        }
        else
        {
            
             result = [YNBroadcastNotificationChat updateBroadcastNotificationWithType:broadcastNotificationType inDatabase:db];
            
            
        }
    }];
    
    return result;
    
}

/**
 修改两人会话撤回状态
 
 @param packId ID
 @return
 */
+(BOOL)updateTwoPeopleChatWithdrawWithPackId:(NSString *)packId
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        
        result = [YNTwoPeopleChat updateTwoPeopleChatWithdrawWithPackId:packId inDatabase:db];
    }];
    
    return result;
    
}


/**
 JC修改群，讨论组，项目组撤回状态
 
 @param packId id
 @param groupType
 @return
 */
+(BOOL)updateManyPeopleMessageWithdrawWithPacketId:(NSString *)packId groupType:(int)groupType
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        
        result = [YNManyPeopleChat updateManyPeopleMessageWithdrawWithPacketId:packId groupType:groupType inDatabase:db];
    }];
    
    return result;
    
}


//查询通知数据
+ (NSArray *)queryBroadNotificationWithType:(YNBroadcastNotificationType)broadcastNotificationType
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    //__block BOOL result;
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    __block NSArray *broadcastNotificationArray;
    
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
       
        broadcastNotificationArray = [YNBroadcastNotificationChat queryBroadcastNotificationWithType:broadcastNotificationType inDatabase:db];
       // result = *rollback;
        dispatch_semaphore_signal(semaphore);
    }];
    dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
    return broadcastNotificationArray;
}



//查询未读通知数据
+ (NSArray *)queryUnReadBroadNotificationWithType:(YNBroadcastNotificationType)broadcastNotificationType
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    __block NSArray *broadcastNotificationArray;
    
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        
        broadcastNotificationArray = [YNBroadcastNotificationChat queryUnReadBroadcastNotificationWithType:broadcastNotificationType inDatabase:db];
        
        dispatch_semaphore_signal(semaphore);
    }];
    dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
    
    return broadcastNotificationArray;
}


//删除通知
+ (BOOL)deleteBroadcastNotificationWithMessageObject:(id)object
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
       
        if ([object isKindOfClass:[NSString class]])
        {
            result = [YNBroadcastNotificationChat deleteBroadcastNotificationWithPacketId:object inDatabase:db];
        }
        else if ([object isKindOfClass:[NSArray class]])
        {
            NSArray *tempArray = (NSArray *)object;
            for (NSString *broadcastId in tempArray)
            {
                result = [YNBroadcastNotificationChat deleteBroadcastNotificationWithPacketId:broadcastId inDatabase:db];
            }
        }
        
        
    
    }];
    
    return result;
}
#pragma end

/**
 *  在登录成功以后, 调用此方法
 *  1.更新两人会话, 将会话中发送中的状态转变成发送失败状态
 *  2.更新多人会话, 将会话中发送中的状态转变成发送失败状态
 *  3.更新最近会话, 将会话中发送中的状态转变成发送失败状态
 */
+ (BOOL)updateMessageSendingStateWhenLoggedIn
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback)
    {
        result = [YNTwoPeopleChat updateMessageSendingStateWithDatabase:db];
        result = [YNManyPeopleChat updateMessageSendingStateWithDatabase:db];
        result = [YNRecentChatObejct updateMessageSendingStateWithDatabase:db];
        //result = *rollback;
    }];
    return result;
}

/**HX** 获取会话列表本地存的指定userNo的未读数 **/
+ (int)queryUnReadWithUserNo:(NSString *)userNo{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block int result=0;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        result=[YNRecentChatObejct queryUnReadWithUserNo:userNo inDatabase:db];
    }];
    return result;
}

/**
 * 根据传来的消息删除对应的会话消息
 */
+ (BOOL)deleteAChatMessageFromMessageData:(YNMessage *)message
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        switch (message.chatType) {
                case YNBubbleMessageChatTypeWeChat:
                case YNBubbleMessageChatTypeWeChatVoice:
                case YNBubbleMessageChatTypeFileWeChat:
                result = [YNTwoPeopleChat deleteAMessageFromDatabaseWithMessageID:message.packetId
                                                              inDatabase:db];
                break;
                case YNBubbleMessageChatTypeGroupChat:
                case YNBubbleMessageChatTypeGroupChatVoice:
                result = [YNManyPeopleChat deleteAMessageFromDatabaseWithMessageID:message.packetId
                                                                groupType:kContact_UserGroupType
                                                               inDatabase:db];
                break;
                case YNBubbleMessageChatTypeDiscussion:
                case YNBubbleMessageChatTypeDiscussionVoice:
                result = [YNManyPeopleChat deleteAMessageFromDatabaseWithMessageID:message.packetId
                                                                groupType:kContact_DiscussionGropType
                                                               inDatabase:db];
                
                break;
            case YNBubbleMessageChatTypeProjectTeamChat:
            case YNBubbleMessageChatTypeProjectTeamVoice:
                result = [YNManyPeopleChat deleteAMessageFromDatabaseWithMessageID:message.packetId
                                                                         groupType:kContact_ProjectTeamGropType
                                                                        inDatabase:db];
                
                break;
            default:
                //debugLog(@"孙大人, 又出现BUG了: %s - %s : %d", __FILE__, __FUNCTION__, __LINE__);
                break;
        }
       // result = *rollback;
        
    }];
    return result;
}

//更新图片消息状态
+ (BOOL)updateMessageImageWithMessage:(YNMessage*)message
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback){
        
        switch (message.chatType) {
            case YNBubbleMessageChatTypeWeChat:
                result = [YNTwoPeopleChat updateMessageWithMessageID:message.packetId
                                             originPhotoUrl:message.originPhotoUrl
                                                   fileName:message.fileName
                                              messageHeight:0.f
                                                 inDatabase:db];
                break;
            case YNBubbleMessageChatTypeGroupChat:
                result = [YNManyPeopleChat updateMessageWithMessageID:message.packetId
                                             originPhotoUrl:message.originPhotoUrl
                                                   fileName:message.fileName
                                              messageHeight:0.f
                                                   groupType:kContact_UserGroupType
                                                 inDatabase:db];
                break;
            case YNBubbleMessageChatTypeDiscussion:
                result = [YNManyPeopleChat updateMessageWithMessageID:message.packetId
                                              originPhotoUrl:message.originPhotoUrl
                                                    fileName:message.fileName
                                               messageHeight:0.f
                                                   groupType:kContact_DiscussionGropType
                                                  inDatabase:db];
                break;
            case YNBubbleMessageChatTypeProjectTeamChat:
                result = [YNManyPeopleChat updateMessageWithMessageID:message.packetId
                                                       originPhotoUrl:message.originPhotoUrl
                                                             fileName:message.fileName
                                                        messageHeight:0.f
                                                            groupType:kContact_ProjectTeamGropType
                                                           inDatabase:db];
                break;
            default:
                break;
        }
        //result = *rollback;
    }];
    
    return result;

}

//更新文件消息状态
+ (BOOL)updateMessageFileStateWithMessage:(YNMessage*)message
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback){
        
        switch (message.chatType) {
            case YNBubbleMessageChatTypeWeChat:

                
               result =  [YNTwoPeopleChat updateMessageFileStateWithMessageID:message.packetId
                                                           fileState:message.fileState
                                                          inDataBase:db];
                break;
            case YNBubbleMessageChatTypeGroupChat:
                
                result = [YNManyPeopleChat updateMessageFileStateWithMessageID:message.packetId
                                                           fileState:message.fileState
                                                            groupType:kContact_UserGroupType
                                                          inDataBase:db];
                break;
            case YNBubbleMessageChatTypeDiscussion:

                result = [YNManyPeopleChat updateMessageFileStateWithMessageID:message.packetId
                                                            fileState:message.fileState
                                                            groupType:kContact_DiscussionGropType
                                                           inDataBase:db];
                break;
            case YNBubbleMessageChatTypeProjectTeamChat:
                
                result = [YNManyPeopleChat updateMessageFileStateWithMessageID:message.packetId
                                                                     fileState:message.fileState
                                                                     groupType:kContact_ProjectTeamGropType
                                                                    inDataBase:db];
                break;
            default:
                break;
        }
        //result = *rollback;
    }];
    
    return result;
}


/**
 *  更新语音已读状态 2016.8.1JC添加
 *
 *  @param message message实体
 *
 *  @return 返回状态
 */
+(BOOL)updateMessageVoiceStateWithMessage:(YNMessage *)message
{
    FMDatabaseQueue *queue = [[XMPPDBManager sharedInstance] achieveQueue];
    __block BOOL result;
    
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback){
        
        switch (message.chatType) {
            case YNBubbleMessageChatTypeWeChatVoice:
            case YNBubbleMessageChatTypeFileWeChat:   
                
                
                result =  [YNTwoPeopleChat updateTwoPeopleChatVoiceStateWithMessageID:message.packetId
                                                                           inDatabase:db];
                break;
            case YNBubbleMessageChatTypeGroupChatVoice:
                
                result = [YNManyPeopleChat updateMessageVoiceStateWithMessageID:message.packetId
                                                                     groupType:kContact_UserGroupType
                                                                    inDataBase:db];
                break;
            case YNBubbleMessageChatTypeDiscussionVoice:
                
                result = [YNManyPeopleChat updateMessageVoiceStateWithMessageID:message.packetId
                                                                     groupType:kContact_DiscussionGropType
                                                                    inDataBase:db];
                break;
            case YNBubbleMessageChatTypeProjectTeamVoice:
                
                result = [YNManyPeopleChat updateMessageVoiceStateWithMessageID:message.packetId
                                                                      groupType:kContact_ProjectTeamGropType
                                                                     inDataBase:db];
                break;
            default:
                break;
        }
        //result = *rollback;
    }];
    
    return result;
}
@end

